var express = require('express');
var router = express.Router();
var mysql = require('mysql');

/* GET home page. */
router.get('/', function (req, res, next) {
    var conn = mysql.createConnection({
        host: 'lcalhost',
        user: 'root',
        password: '123456',
        database:'stumaneger'
    });
    conn.connect(err=>{
        if(err) console.log('数据库连接失败！\n'+err.stack);
        else console.log('数据库连接成功！');
    });
    var strSQL = 'select * from students';
    conn.query(strSQL,(err,result)=>{
        if(err){
            console.log('查询出错！');
            conn.end();
            res.send('查询出错！');
        }else{
           // console.log(result);
           // res.send('');
           res.render('studentlist',{
            title: '学生信息表',
            data: result
           })
        }
    });

});

module.exports = router;